package com.zbj.springboot.mybatis.service.impl;

import com.github.pagehelper.PageHelper;
import com.zbj.springboot.mybatis.dao.entity.DeveloperInfo;
import com.zbj.springboot.mybatis.dao.entity.DeveloperInfoExample;
import com.zbj.springboot.mybatis.dao.mapper.DeveloperInfoMapper;
import com.zbj.springboot.mybatis.service.DeveloperInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * DeveloperInfoServiceImpl
 *
 * @author weigang
 * @create 2018-04-17
 **/
@Service
public class DeveloperInfoServiceImpl implements DeveloperInfoService {

    @Resource
    private DeveloperInfoMapper developerInfoMapper;

    @Resource
    private DeveloperInfoMapper developerInfoMapperSlave;

    @Override
    public int update(DeveloperInfo info) {
        DeveloperInfoExample example = new DeveloperInfoExample();
        example.or().andDeveloperIdEqualTo(1000007474L);
        return developerInfoMapper.updateByExampleSelective(info, example);
    }

    @Override
    public List<DeveloperInfo> list(DeveloperInfo info) {
        DeveloperInfoExample example = new DeveloperInfoExample();
        DeveloperInfoExample.Criteria criteria = example.or();
        if (!ObjectUtils.isEmpty(info.getDeveloperId())) {
            criteria.andDeveloperIdEqualTo(info.getDeveloperId());
        }

        if (!ObjectUtils.isEmpty(info.getValid())) {
            criteria.andValidEqualTo(info.getValid());
        }

        PageHelper.startPage(1, 10);
        PageHelper.orderBy("update_time desc");
        List<DeveloperInfo> infoList = developerInfoMapperSlave.selectByExample(example);
        return infoList;
    }
}